import {
	defineConfig
} from 'vite';
import path from 'path';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import {
	ElementPlusResolver
} from 'unplugin-vue-components/resolvers';

export default defineConfig({
	define: {
		__VUE_OPTIONS_API__: true,
		__VUE_PROD_DEVTOOLS__: false,
		__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
	},
	plugins: [
		vue(),
		Components({
			dirs: ['src/components'], // 仅自动导入组件目录
			resolvers: [ElementPlusResolver()],
			directoryAsNamespace: true,
			// dts: 'src/components.d.ts', // 生成类型声明
		}),
	],
	resolve: {
		alias: {
			'@': path.resolve(__dirname, './src'),
		},
	},
	server: {
		historyApiFallback: {
			rewrites: [{
				from: /^\/.*/,
				to: '/index.html'
			}],
		},
	},
	build: {
		rollupOptions: {
			output: {
				manualChunks: {
					vue: ['vue', 'vue-router'],
					elementPlus: ['element-plus'],
				},
			},
		},
	},
});